package com.elite.controller;

import com.alibaba.fastjson.JSON;
import com.elite.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.logging.Logger;

/**
 * Created by hbl on 2017/3/30.
 */

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    HttpSession session;

    private static final Logger LOGGER = Logger.getLogger(String.valueOf(LoginController.class));

    @RequestMapping("/loginResult")
    public String login(){


        String result =null;
        if (session.getAttribute("loginUser")!=null){
LOGGER.info("--------------------------->>>>>>>>123");
            User user = (User) session.getAttribute("loginUser");
            if (user!=null){
                result = "true";
            }

        }else {
            result = "false";
        }

        return JSON.toJSON(result).toString();
    }

    @RequestMapping("/returnUser")
    public String returnUser(){

        String result ="false";
        if (session.getAttribute("loginUser")!=null){

            User user = (User) session.getAttribute("loginUser");
            if (user!=null){
                return JSON.toJSON(user).toString();
            }

        }
        return JSON.toJSON(result).toString();
    }


}
